//
//  LoginViewModel.swift
//  CarShare
//
//  Created by XQ on 2018/1/6.
//

import UIKit

class LoginViewModel: NSObject {
    
    /// 用户登录请求
    
    func requestLogin(para: [String : AnyObject], completion: @escaping (_ isSuccess: Bool, _ msg: String?) -> ()) {
        
        NetworkTool.request(url: URL_Login_Login, parameter: para) { (result, isSuccess, msg) in
            
            if isSuccess {
                
                guard let deviceID = para["device_id"] as? String,
                    let data = result?["data"] as? [String : AnyObject],
                    let user = data["user"] as? [String : AnyObject],
                    let token = data["token"] as? String,
                    let userSig = data["user_sig"] as? String else {
                        
                        return
                }
                
//                let userMap = Map(mappingType: .fromJSON, JSON: user)
//                let _ = UserModel.objectForMapping(map: userMap)
//                UserModel.shared.token = token
//                
//                UserDefaults.standard.set(UserModel.shared.id, forKey: kUserId)
//                UserDefaults.standard.set(token, forKey: kToken)
//                UserDefaults.standard.synchronize()
                
                
            } else {
                
                completion(isSuccess, msg)
            }
        }
    }


}
